// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import echarts from 'echarts'
import * as api from './api/api'
import { MessageBox } from 'element-ui'
import axios from 'axios'
import Vuex from 'vuex'


Vue.prototype.$api = api
Vue.config.silent = true
Vue.prototype.$echarts = echarts
Vue.use(Vuex)
Vue.use(ElementUI)
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	template: '<App/>',
	components: {
		App
	}
})


// 添加一个响应拦截器
axios.interceptors.response.use(response => {
  return new Promise((resolve, reject) => {
    if (response.data.code === '000000') {
      resolve(response)
    } else if (response.data.code === '000100') {
      router.push('/login')

    } else {
      reject(response.data)
    }
  })
}, (error) => {
  console.log(error)
  return Promise.reject({ msg: '系统错误' })
})
